﻿<UserControl x:Class="NoMvvm.Demo.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:helpers="clr-namespace:NoMvvm.Demo.Silverlight.Helpers"
    xmlns:nomvvm="clr-namespace:NoMvvm;assembly=NoMvvm"
    mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400">

    <!--This converter just helps us bind a bool to a Visibility-->
    <UserControl.Resources>
        <helpers:BooleanToVisibilityConverter x:Key="Converter" />
    </UserControl.Resources>

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <nomvvm:EventToCommand Command="{Binding [Refresh]}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <!--Refresh button-->
        <Button HorizontalAlignment="Left" Width="150" Height="30" Command="{Binding [Refresh]}">Refresh</Button>

        <!--List of our planets-->
        <ListBox Grid.Row="1" ItemsSource="{Binding [Planets]}" HorizontalContentAlignment="Stretch">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Width="250">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBlock VerticalAlignment="Center" Text="{Binding [Name]}" />
                        <TextBlock VerticalAlignment="Center" Grid.Column="1" Text="{Binding [Diameter]}" HorizontalAlignment="Right" />
                        <Button Grid.Column="3" Margin="5" Command="{Binding [Info]}">Info</Button>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <!--Our busy indicator-->
        <TextBlock 
            Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" 
            Text="Please Wait..." Visibility="{Binding [IsBusy], Converter={StaticResource Converter}}" />

    </Grid>
</UserControl>
